﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Client_Web.ServiceReference;

namespace Client_Web.Account
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            RegisterHyperLink.NavigateUrl = "Register.aspx?ReturnUrl=" + HttpUtility.UrlEncode(Request.QueryString["ReturnUrl"]);
        }

        protected void Authentifier_Click(object sender, EventArgs e)
        {
            ServiceClient serviceClient = new ServiceClient();

            int userId;
            string result = serviceClient.connectUser(LoginUser.UserName, LoginUser.Password);
            if(int.TryParse(result, out userId)) {
                Session["userId"] = userId;
                Session["userLogin"] = LoginUser.UserName;
            } else {
                
                LoginUser.FailureText = result;
            }
        }
    }
}
